import 'package:base_flutter/base_flutter.dart';
import 'package:ls_work/a_yyt/models/medical_elder_entity.dart';
import 'package:ls_work/config/global_configs.dart';
import 'package:ls_work/ui/choose_multi_elder_page.dart';
import 'package:ls_work/util/event_bus.dart' as e;


class ElderFilterSettingViewModel extends BaseViewModel {
  ElderFilterSettingViewModel(super.context);

  var elderList = false;

  var nurseUse = false;

  var mealUse = false;

  List<MedicalElderInfo> filterOld = [];

  @override
  void onCreated() {
    super.onCreated();
    elderList = GlobalConfigs.elderUseFilter;
    nurseUse = GlobalConfigs.nurseUseFilter;
    mealUse = GlobalConfigs.mealUseFilter;
    filterOld.addAll(GlobalConfigs.savedFilterElder);
    notifyListeners();
  }

  Future<void> toChooseElder() async {
    var data = await Go().push(ChooseMultiElderPage(filterOld: filterOld,));
    if (data != null) {
      filterOld = data as List<MedicalElderInfo>;
      notifyListeners();
    }
  }

  Future<void> saveFilterSetting() async {
    if(filterOld.isEmpty){
      showToast("请选择长者");
      return;
    }
    var oldElderUse = GlobalConfigs.elderUseFilter;
    await GlobalConfigs.saveOldFilter(
        elderUseFilter: elderList,
        nurseUseFilter: nurseUse,
        mealUseFilter: mealUse,
        filterOld: filterOld);
    Go().pop();
    e.eventBus.emit("refreshElder");
  }
}
